<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    width="740px"
    :visible="visible"
    :append-to-body="true"
    :close-on-click-modal="false"
    custom-class="ele-dialog-form"
    :title="isUpdate ? '提现审核' : '提现审核'"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="提现金额:" prop="apply_amount">
        <el-input
          disabled
          clearable
          v-model="form.apply_amount"
          placeholder="提现金额"
        />
      </el-form-item>

       <el-form-item label="手续费:" prop="handling_fee">
        <el-input
          disabled
          clearable
          v-model="form.handling_fee"
          placeholder="手续费"
        />
      </el-form-item>
      <el-form-item label="打款金额:" prop="amount">
        <el-input
          disabled
          clearable
          v-model="form.amount"
          placeholder="打款金额"
        />
      </el-form-item>
      <!-- <el-form-item label="店铺名称:" prop="store_name">
        <el-input
          clearable
             disabled
          v-model="form.storeInfo.store_name"
          placeholder="店铺名称"
        />
      </el-form-item>



      <el-form-item label="店铺手机号:" prop="type">
        <el-input
          clearable
             disabled
          v-model="form.storeInfo.telphone"
          placeholder="店铺手机号"
        />
      </el-form-item> -->

      <el-form-item label="收款账号:" prop="account">
        <el-input
          clearable
          disabled
          v-model="form.account"
          placeholder="收款账号"
        />
      </el-form-item>

      <el-form-item label="姓名:" prop="name">
        <el-input clearable disabled v-model="form.name" placeholder="姓名" />
      </el-form-item>

      <el-form-item label="银行名称:" prop="bank_name">
        <el-input
          clearable
          disabled
          v-model="form.bank_name"
          placeholder="银行名称"
        />
      </el-form-item>

      <el-form-item label="状态:" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio :label="2" value="2">审核通过</el-radio>
          <el-radio :label="3" value="3">驳回</el-radio>
        </el-radio-group>
      </el-form-item>

         <el-form-item label="驳回原因:" prop="reason"  v-if="form.status == 3">
      <el-input clearable v-model="form.reason" placeholder="驳回原因" />
    </el-form-item>
    </el-form>

    

 
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消 </el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >保存
      </el-button>
    </template>
  </ele-modal>
</template>

<script>
import { add, update } from '@/api/withdraw';
const DEFAULT_FORM = {
  id: 0,
  withdraw_rate: '',
  apply_amount: '',
  amount: '',
  type: '',
  account: '',
  
  bank_name: '',
  name: '',
  status: '',
  reason: ''
};

export default {
  name: 'OpenEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: { ...DEFAULT_FORM },
      // 表单验证规则
      rules: {
        name: [
         
        ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  methods: {
    /* 保存编辑 */
    modalPicTap(tit, picTit, openTitle) {
      this.modalTitle = openTitle;
      this.isChoice = tit === 'dan' ? '单选' : '多选';
      this.picTit = picTit;
      this.modalPic = true;
    },
    // 选中图片
    getPic(pc) {
      switch (this.picTit) {
        case 'pic_url':
          this.form.pic_url = pc.satt_dir;
          break;
        case 'background':
          this.form.background = pc.satt_dir;
          break;
      }
      this.modalPic = false;
    },
    //删除图片
    handleRemove(field) {
      this.form[field] = '';
    },

    save() {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return false;
        }

        this.loading = true;
        const data = {
          ...this.form
        };

        const saveOrUpdata = this.isUpdate ? update : add;

        saveOrUpdata(data)
          .then((msg) => {
            this.loading = false;
            this.$message.success(msg);
            this.updateVisible(false);
            this.$emit('done');
          })
          .catch((e) => {
            this.loading = false;
            this.$message.error(e.message);
          });
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  },
  watch: {
    visible(visible) {
      if (visible) {
        if (this.data) {
          this.$util.assignObject(this.form, {
            ...this.data
          });
          this.isUpdate = true;
        } else {
          this.isUpdate = false;
        }
      } else {
        this.$refs['form'].clearValidate();
        this.form = { ...DEFAULT_FORM };
      }
    }
  }
};
</script>
